package com.chey.service.impl;

import com.chey.dao.ApplyDao;
import com.chey.dao.ArptDao;
import com.chey.domain.Arpt;
import com.chey.domain.Updata;
import com.chey.service.ApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author JanYao
 * @version 0.1
 */
@Service
public class ApplyServiceImpl implements ApplyService {
    @Autowired
    private ApplyDao applyDao;
    @Autowired
    private ArptDao arptDao;

    @Override
    public Integer apply(Updata updata) {
        System.out.println("原始数据"+updata);
        //状态为1时，表示同意，更新数据
        //同时把源数据表更新为最新数据
        if ("1".equals(updata.getStatus())){
            List<String> arptUUID = arptDao.findArptUUID(updata.getFlid(), updata.getCfno());
            for (String s : arptUUID) {
                List<Arpt> arptS = arptDao.findArptS(s);
                for (Arpt arpt :arptS) {
                    if (arpt.getFPTT() !=updata.getStartTime()){
                        arptDao.updateS(updata.getStartTime(),s);
                    }
                }

                List<Arpt> arptE = arptDao.findArptE(s);
                for (Arpt arpt :arptE) {
                    if (arpt.getFPTT() !=updata.getEndTime()){
                        arptDao.updateE(updata.getEndTime(),s);
                    }
                }
            }

            Integer update = applyDao.update(updata);

            return update;
        }else {
            Integer apply = applyDao.apply(updata);
            return apply;
        }

    }

    @Override
    public List<Updata> query() {
        return applyDao.select();
    }
}
